import 'dart:convert';
import 'dart:math';

import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:graphic/graphic.dart';
import 'package:whale/helper/utils/util.dart';
import '../index.dart';
import 'RadarProvider.dart';

class LevelDataView extends GetView<WatchController> {
  const LevelDataView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    Map<String, List<double>> dataList1 = Map();

    var colors = [
      Color(0xff179523),
      Color(0xffC34949),
      Color(0xffB59A7A),
      Color(0xff5EA1D9),
    ];
    List<double> data1 = [];
    double maxValue = 5;
    controller.state.lievDatas!.forEach((element) {
      data1.add(element.riskLevelSum?.toDouble() ?? 0);
      if((element.riskLevelSum?.toDouble() ?? 0)>maxValue){
        maxValue = element.riskLevelSum!.toDouble();
      }
    });
    dataList1[''] = data1;
    return SizedBox(
      width: 1.sw,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            '违规程度统计',
            style: TextStyle(
                color: ColorsUtil.title,
                fontSize: 16.sp,
                fontWeight: FontWeight.bold),
          ),
          Stack(
            children: [
              Center(
                child: Container(
                  margin: EdgeInsets.only(top: 30.r),
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(2.r),
                  ),
                  width: 1.sw,
                  height: 270.r,
                ),
              ),
              Container(
                width: 1.sw,
                // height: 320.r,
                margin: EdgeInsets.only(top: 15.r),
                child: BrnRadarChart(
                  radius: 100.r,
                  provider: RadarProvider(4, dataList1),
                  sidesCount: 4,
                  markerMargin: 4,
                  levelCount: 5,
                  maxValue: maxValue,
                  crossedAxisLine: true,
                  rotateAngle: 0,
                  builder: (index) {
                    return Container(
                      width: 50.r,
                      height: 50.r,
                      decoration:
                          BoxDecoration(color: Colors.white, boxShadow: [
                        BoxShadow(
                            color: Color(0xff123988).withOpacity(0.16),
                            offset: Offset(0, 2), //阴影y轴偏移量
                            blurRadius: 4, //阴影模糊程度
                            spreadRadius: 0.4 //阴影扩散程度
                            ),
                      ]),
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Text(
                            '${controller.state.lievDatas![index].riskLevelSum}',
                            style: TextStyle(
                                color: ColorsUtil.title,
                                fontSize: 13.r,
                                fontWeight: FontWeight.bold),
                          ),
                          Text(
                            controller.state.lievDatas![index].riskLevel
                                .toString(),
                            style:
                                TextStyle(color: colors[index], fontSize: 10.r),
                          ),
                        ],
                      ),
                    );
                  },
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }
}
